# Maintainer: Leonidas Spyropoulos (artafinde@archlinux.org)
# Contributor: scrawler@gmail.com

pkgname=freeplane
_majorver=1
_minorver=11
_patchver=1
_updatever=1
pkgver=${_majorver}.${_minorver}.${_patchver}
_git_tag=${_majorver}.${_minorver}.${_patchver}
pkgrel=1
pkgdesc="A Java mindmapping tool"
arch=('any')
url="http://freeplane.sourceforge.net"
license=('GPL2')
_jrever=11
_jdkver=17
makedepends=('gradle' "jdk${_jdkver}-openjdk" 'gnu-free-fonts' 'fontconfig' 'unzip')
depends=("java-runtime>=${_jrever}" "java-runtime<=${_jdkver}")
source=("https://downloads.sourceforge.net/sourceforge/${pkgname}/${pkgname}_src-${_git_tag}.tar.gz"
        "freeplane.desktop" "freeplane.run"
        "0001-Upgrade-ospackage-plugin-to-support-gradle-8.patch::https://github.com/inglor/freeplane/commit/eed47d2a031d802e26ebf8cb9b1488880f865ec3.patch"
        "0002-Add-dependsOn-for-tasks-which-fail-with-gradle-8.x.patch::https://github.com/inglor/freeplane/commit/14c0323bff8436ec3ea31b99b9daeea6ee0e52cc.patch")
b2sums=('aae53ac69f3c7001e67deffe8ed69e86b052669134086ee7359d96c0028eca98bc5d51cc0972312debc0e5217ab11f9892665ab41d00bf509a42508315fb23a9'
        '87c25331e01823e38668e4b394a51a279c05b24b088f4ffc1482d3783e24018da8f9e51b3ad1a62c5a863f85a6ccb30bbe8999cb861dc1b93d5483019644cfa5'
        '24ca56b7c7894b9bb38600b4d37973769243e1bdb221f33125b60bf4f878a3b630775710fab9dee97fa45a69319455037e294860ba7fbd608529982c6b0b1538'
        '9be6499332930904b105b5de510988df727088a343ae3735cda30e7df619bf041125d38ca874a462cd811f552e9c02624ad0ec2ef54524530c1d61d5945309ec'
        '104ead0a6baa24ed623ea12e25c352e301123bfd2c406610910650e1a02e959b5d998c01b89e270d89bbb70981242b283d52c161943f9fc8fd00d2ab3243ccda')

prepare() {
  cd "$pkgname-$_git_tag"
  patch -Np1 < "${srcdir}/0001-Upgrade-ospackage-plugin-to-support-gradle-8.patch"
  patch -Np1 < "${srcdir}/0002-Add-dependsOn-for-tasks-which-fail-with-gradle-8.x.patch"
}

build() {
  cd "$pkgname-${_git_tag}"
  export JAVA_HOME="/usr/lib/jvm/java-$_jdkver-openjdk"
  export PATH="/usr/lib/jvm/java-$_jdkver-openjdk/bin:$PATH"
  /usr/bin/gradle -Dorg.gradle.daemon=false build dist

  install -dm755 "$srcdir/$pkgname-${_git_tag}/dist"
  unzip -d "$srcdir/$pkgname-${_git_tag}/dist" \
    "$srcdir/$pkgname-${_git_tag}/DIST/${pkgname}_bin-${_majorver}.${_minorver}.${_patchver}.zip"
}

package() {
  install -dm755 "$pkgdir/usr/share/freeplane/"
  cd "$srcdir/$pkgname-${_git_tag}/dist/$pkgname-${_majorver}.${_minorver}.${_patchver}"
  cp -dr --no-preserve='ownership' core doc plugins resources scripts framework.jar freeplane.l4j.ini \
    freeplane.png freeplane.policy freeplane.sh freeplaneConsole.l4j.ini freeplaneIcons.dll \
    freeplanelauncher.jar gitinfo.txt init.xargs license.txt props.xargs \
    "$pkgdir/usr/share/freeplane/"

  # Install license
  install -dm755 "$pkgdir/usr/share/licenses/$pkgname"
  mv license.txt "$pkgdir/usr/share/licenses/$pkgname/license.txt"

  # Install icons
  install -dm755 "$pkgdir/usr/share/pixmaps/"
  mv freeplane.svg "$pkgdir"/usr/share/pixmaps/freeplane.svg

  # Install the desktop entry
  install -Dm644 "$srcdir/freeplane.desktop" "$pkgdir"/usr/share/applications/$pkgname.desktop

  # Install the executable script
  install -Dm755 "$srcdir/freeplane.run" "$pkgdir"/usr/bin/freeplane
}

# vim:set ft=sh sw=2 sts=2 et:
